package com.briup.cms.web.controller;

import com.briup.cms.bean.Carousel;
import com.briup.cms.service.ICarouselService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Layla
 * @version 1.0
 * @date 2021/7/18 17:01
 */

@Api(tags = "轮播图接口")
@RestController
@RequestMapping("/auth/carousel")

public class CarouselController {
    @Autowired
    private ICarouselService service;


    //删除轮播图
    @ApiOperation(value = "删除轮播图")
    @DeleteMapping("/deleteById")
    public Message deleteById(Integer id){
        service.deleteById(id);
        return MessageUtil.success(id);
    }



//查询已启用轮播页
@ApiOperation(value ="查询已启动轮播图")
    @GetMapping("/find/yes")
    public Message find(){
        List<Carousel> list= service.findYesCarousel();
        return  MessageUtil.success(list);
    }



    //分页查询
    @ApiOperation(value ="分页查询轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,paramType = "query")
    })

    @GetMapping("/page/query")
    public Message query(int pageNum,int pageSize){
        PageInfo<Carousel> pageInfo= service.findAll(pageNum, pageSize);
        return MessageUtil.success(pageInfo);
}


//添加轮番页
@ApiOperation(value = "保存轮播页")
@PostMapping("/save")
public Message save(Carousel carousel){
    service.saveCarousel(carousel);
    return MessageUtil.success(carousel);
}


//更新轮播图
@ApiOperation("更新轮播图")
@PutMapping("/update")
public Message update(Carousel carousel){
    service.updateCarousel(carousel);
    return MessageUtil.success(carousel);
}
}


